//
//  BQShopCollectionViewCell.m
//  BeeQuick
//
//  Created by Asun on 2017/7/10.
//  Copyright © 2017年 BecomeRich. All rights reserved.
//

#import "BQShopCollectionViewCell.h"

@interface BQShopCollectionViewCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImgView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UIImageView *jingxuanImageView;
@property (weak, nonatomic) IBOutlet UIImageView *buyOneImageView;


@property (weak, nonatomic) IBOutlet UILabel *specificsLabel;

@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
@property (weak, nonatomic) IBOutlet UILabel *market_priceLabel;


@property (weak, nonatomic) IBOutlet UIButton *decreaseBtn;
@property (weak, nonatomic) IBOutlet UILabel *countLabel;

@property (nonatomic, assign) NSInteger count;

@end

@implementation BQShopCollectionViewCell



- (void)setShopModel:(BQShop *)shopModel{
    _shopModel = shopModel;
    
    [self.iconImgView sd_setImageWithURL:[NSURL URLWithString:shopModel.img] placeholderImage:[UIImage imageNamed:@"v2_placeholder_half_size"]];
    
    self.nameLabel.text = shopModel.name;
    
    self.specificsLabel.text = shopModel.specifics;
    
    self.priceLabel.text = [NSString stringWithFormat:@"$%@",shopModel.price];
    
    self.market_priceLabel.text = [NSString stringWithFormat:@"$%@",shopModel.market_price];
    
    self.buyOneImageView.hidden = !shopModel.had_pm;
    
    self.decreaseBtn.hidden = YES;
    
    self.countLabel.hidden = YES;
}


- (IBAction)decrease:(UIButton *)sender {

    self.countLabel.text = [NSString stringWithFormat:@"%zd",--self.count];
    
    if (self.count == 0) {
        self.decreaseBtn.hidden = YES;
        self.countLabel.hidden = YES;
    }
}
- (IBAction)increase:(UIButton *)sender {

    
    self.countLabel.hidden = NO;
    self.decreaseBtn.hidden = NO;
    
    self.countLabel.text = [NSString stringWithFormat:@"%zd",++self.count];
    
    
    CGPoint center = self.iconImgView.center;
    
    CGPoint targetPoint = [self.iconImgView convertPoint:center toView:kWindow];
    
    NSValue *targetValue = [NSValue valueWithCGPoint:targetPoint];
    
 [[NSNotificationCenter defaultCenter] postNotificationName:ToValueNotificationName object:self.shopModel userInfo:@{@"point":targetValue}];
}

@end
